﻿   import Taro, { Component } from '@tarojs/taro'
import { Swiper, SwiperItem, Image, View, Text } from '@tarojs/components'
import '../../assets/common.scss'
import CommonJs from '../../utils/common'
import Footer from '../index/footer'
import './my.scss'

import dd01 from '../../assets/kedouimg01/dd01.png'
import dd02 from '../../assets/kedouimg01/dd02.png'
import dd03 from '../../assets/kedouimg01/dd03.png'
import dd04 from '../../assets/kedouimg01/dd04.png'
import dd05 from '../../assets/kedouimg01/dd05.png'
import hyk from '../../assets/kedouimg01/vip3.png'
import ewm from '../../assets/kedouimg01/ewmtb.png'
import photo from '../../assets/kedouimg01/tongshi.png'

export default class Index extends Component {
  constructor(props) {
    super(props);
    this.state = {
      userinfo:Taro.getStorageSync('userinfo'),  
      dateinfo:Taro.getStorageSync('dateinfo'),  
      balanceXfj:0,
      balanceGxj:0,
      balanceXfgf:0,
      balanceWdt:0,
      balanceZxzc:0,
      indexAssets:0,
      creditBalance:0,  
      totalWdt:0,
		  lockUpWdt:0,
		  lockUpWdtFormula:0,
      platformLockUpWdt:0,
      totalUc:0,
      totalWdt:0,
      balance:0,
      beanBalance:0,
      indexK:0,
      indexCI:0,
      indexAssets:0,
      indexAssetsFormula:'',
      balanceCyzs:0,
	    indexCIFormula:0,
      coxcommit:false,
      couponlist:[],
      card:[],
      order:{
      	ucNum:0,
      	wucNum:0
      },
      tgmonery:0,
      jmlist:'',
      zjinfo:{
      	balanceCreditUc:0
      },
      noshow:CommonJs.getshow(),
      noshow1:CommonJs.getshow(),
      appmark:CommonJs.getmark()
    }
  }
  config = {
    navigationBarTitleText: '我的'
  }
  componentWillMount () {
//	var id=Taro.getStorageSync('dateinfo').qid;
//	if(!id){
//		CommonJs.open('/pages/grouplist/grouplist')
//	}
    this.financeView();
    this.getcoupon();
    this.getcard();
    this.getshow();
    this.getright();
    this.getjmname();
  }
  componentDidShow () {
    
    this.financeView();
    this.getcoupon();
    this.getcard();
    this.getshow();
    this.getright();
    this.getjmname();
    this.setState({
      userinfo:Taro.getStorageSync('userinfo'),
      dateinfo:Taro.getStorageSync('dateinfo')
    })
    
  }
  opendetails(url,type){
    var _this = this
    if (type == 1) {
      _this.$preload({
        money:_this.state.balance
      })
    } else if (type == 2) {
      _this.$preload({
        money:_this.state.creditBalance
      })
    }
    else if (type == 3) {
      _this.$preload({
        money:_this.state.beanBalance
      })
    }
    else if (type == 4) {
      _this.$preload({
        money:_this.state.balanceXfj
      })
    }
    else if (type == 5) {
      _this.$preload({
        money:_this.state.balanceGxj
      })
    }
    else if (type == 6) {
      _this.$preload({
        money:_this.state.balanceXfgf
      })
    }
    else if (type == 7) {
      _this.$preload({
        money:_this.state.balanceWdt,
        totalWdt:_this.state.totalWdt,
	    	lockUpWdt:_this.state.lockUpWdt,
	    	lockUpWdtFormula:_this.state.lockUpWdtFormula,
	    	platformLockUpWdt:_this.state.platformLockUpWdt
      })
    }
    else if (type == 8) {
      _this.$preload({
        money:_this.state.indexK,
        totalUc:_this.state.totalUc,
        totalWdt:_this.state.totalWdt
      })
    }
    else if (type == 9) {
      _this.$preload({
        money:_this.state.indexCI,
        indexCIFormula:_this.state.indexCIFormula,
        balanceCyzs:_this.state.balanceCyzs
      })
    }
    else if (type == 10) {
      _this.$preload({
        money:_this.state.balanceXfgf,
        indexAssets:_this.state.indexAssets,
        indexAssetsFormula:_this.state.indexAssetsFormula,
      })
    }
    else if (type == 11) {
      _this.$preload({
        money:_this.state.balanceZxzc
      })
    }
    else if (type == 'UC'||type=='WUC') {
      _this.$preload({
        malltype:type
      })
    }
    CommonJs.openTo(url)
  }
  opendetails1(url,id){
  	
      this.$preload('pagename',id);
      CommonJs.openTo(url);
    }
  financeView(){
    var _this=this
    var date1={}
    // console.log(JSON.stringify(date1)+'date1')
    CommonJs.ajaxRequest('/crm/papi/v1.9/currency/getAcccountCurrency',date1,'GET',function(res){
    	var ret=res.data
  		_this.setState({
  		  zjinfo:ret,
          balanceXfj:ret.balanceXfj,
          balanceGxj:ret.balanceGxj,
          balanceXfgf:ret.balanceXfgf,
          balanceWdt:ret.balanceWdt,
          balanceZxzc:ret.balanceZxzc,
          creditBalance:ret.creditBalance,
          balance:ret.balance,
          beanBalance:ret.beanBalance,
          indexAssets:ret.indexAssets,
          indexK:ret.indexK,
          indexCI:ret.indexCI,
          totalWdt:ret.totalWdt,
		  lockUpWdt:ret.lockUpWdt,
		  lockUpWdtFormula:ret.lockUpWdtFormula,
          platformLockUpWdt:ret.platformLockUpWdt,
          totalUc:ret.totalUc,
          totalWdt:ret.totalWdt,
          indexAssets:ret.indexAssets,
	      indexAssetsFormula:ret.indexAssetsFormula,
          indexCIFormula:ret.indexCIFormula,
          balanceCyzs:ret.balanceCyzs,
        })
    },'wfw')
  }
  open(url){
		CommonJs.openTo(url)
	}
  goorder(url,type){
  	var appmark=this.state.appmark;
  	var obj={}
  	if(appmark=='xjzb'){
  		obj.type=type;
  		obj.malltype='UC'
  	}
  	else{
  		obj.type=type;
  	}
	this.$preload(obj)
    CommonJs.openTo(url);
  }
  gotowgm(url,type){
  	this.$preload({
  		type:type
  	})
  	CommonJs.openTo(url)
  }
  getcoupon(){
  	var url="/crm/papi/v1.9/coupon";
  	var dates={
  		"couponStatus.in":"RECEIVED",
  		size:10,
  		page:0
  	}
  	var _this=this
  	CommonJs.ajaxRequest(url,dates,'GET',function(res){
		_this.setState({
	      couponlist:res.data.list
	    })
  	},"wfw")
  }
  openxq(mid,id){
  	this.$preload({
	  	mid:mid,
	  	couponid:id,
	  	byfrom:'my'
		})
  	this.open("/pages/coupon/details");
  }
  getcard(){
  	var url='/shop/papi/v1.9/members/card/bag'
  	var _this=this
  	CommonJs.ajaxRequest(url,'','GET',function(res){
		_this.setState({
	      card:res.data
	    })
  	},"wfw")
  }
  getshow(){
	var webinfo=Taro.getStorageSync('webinfo')
	if(webinfo){
		this.setState({
		  noshow:-1
		})
	}
	else{
		var url='/advert/papi/v1.9/advert/advert/state'
		var _this=this
		CommonJs.ajaxRequest(url,'','GET',function(res){
			if(res.data.type==_this.state.noshow1){
				_this.setState({
				  noshow:-1
				})
			}
			else{
				_this.setState({
				  noshow:res.data.type
				})
			}
		},"wfw")
	}
  }
  getright(){
  	var url='/order/papi/v1.9/order/statusNum/byUser' 
  	var _this=this
  	CommonJs.ajaxRequest(url,'','GET',function(res){
  		if(_this.state.appmark=='xjzb'){
  			var url1='/order/papi/v1.9/order/statusNum/8' 
  			CommonJs.ajaxRequest(url1,'','GET',function(ret){
  				var ucNum=res.data.unpaidNum+res.data.deliveredNum+res.data.goodsReceivedNum
  				var red=ret.data;
  				red.ucNum=ucNum
  				red.wucNum=res.data.wucNum
  				_this.setState({
			      order:red
			    })
  			},"wfw")
  		}
  		else{
			_this.setState({
		      order:res.data
		    })
		}
  	},"wfw")
  	
  	
  }
  getjmname(){
    Taro.showToast({
	  	title:'加载中',
	  	icon: 'none',
	  	duration: 1000
	  })
  	var _this=this
  	CommonJs.ajaxRequest('/bond/getUserBondGradeSetting','','GET',function(res){
      _this.setState({
        jmlist: res.content
      });
  	})
  }
  
  
  render () {
         //<View className='active-order' onClick={this.opendetails.bind(this,'/pages/my/activety')}>
        //   <Image mode='scaleToFill' className='active-photo' src='https://minichat.g2ma.com/kedouimg/myorder20.png'></Image>
        //   <Text className=''>活动订单</Text>
        // </View>
        const result = this.state.couponlist
        const appmark=this.state.appmark
    return (
      <View className='page'>
        <View className='my-mes'>
          <Image mode='scaleToFill'  onClick={this.opendetails1.bind(this,'/pages/persinfo/persinfo',this.state.dateinfo.userid)} className='my-photo' src={this.state.userinfo.avatarUrl?this.state.userinfo.avatarUrl:photo}></Image>
          <View className='my-name' onClick={this.opendetails1.bind(this,'/pages/persinfo/persinfo',this.state.dateinfo.userid)}>
            <View className='my-names'>{this.state.userinfo.nickName}</View>
    <View className='my-names'>{this.state.dateinfo.userid}号{this.state.jmlist==null?'创客':this.state.jmlist.gradeSettingName}</View>
          </View>
          
          <View className='myewm' style={this.state.noshow==-1?'display:none':''} onClick={this.open.bind(this,'/pages/my/myewm')}><Image className="img" mode="widthFix" src={ewm}></Image></View>
        </View>
        <View className='my-money' style={this.state.noshow==-1?'display:none':''}>
         
          <View className='my-wdyue' onClick={this.opendetails.bind(this,'/pages/my/xfjlist',4)} style={appmark=='xjzb'?'':'display:none'}>
            <Text className='my-jinezngcn my-wdjifens'>{this.state.balanceXfj/100}</Text>
            <Text className='my-jinezngcn my-wdyejf'>消费金</Text>
          </View>
          <View className='my-wdyue' onClick={this.opendetails.bind(this,'/pages/my/gxjlist',5)}>
            <Text className='my-jinezngcn my-wdzhubi'>{this.state.balanceGxj/100}</Text>
            <Text className='my-jinezngcn my-wdyejf' style={appmark=='xjzb'?'':'display:none'}>共享金</Text>
            <Text className='my-jinezngcn my-wdyejf' style={appmark=='xjzb'?'display:none':''}>收益金</Text>
          </View> 
          <View className='my-wdyue' onClick={this.opendetails.bind(this,'/pages/my/xflist',6)}>
            <Text className='my-jinezngcn my-wdzhubi' style='color:#29ab91;'>{this.state.balanceXfgf/100}</Text>
            <Text className='my-jinezngcn my-wdyejf' style={appmark=='xjzb'?'':'display:none'}>消费工分</Text>
            <Text className='my-jinezngcn my-wdyejf' style={appmark=='xjzb'?'display:none':''}>消费额</Text>
          </View> 
          <View className='my-wdyue' onClick={this.opendetails.bind(this,'/pages/my/wdt',7)}>
            <Text className='my-jinezngcn my-wdzhubi' style='color:#1c89f0;'>{this.state.balanceWdt/100}</Text>
            <Text className='my-jinezngcn my-wdyejf' style={appmark=='xjzb'?'':'display:none'}>WDT</Text>
            <Text className='my-jinezngcn my-wdyejf' style={appmark=='xjzb'?'display:none':''}>勋章</Text>
          </View> 
        </View> 
        
        <View className='my-money' style={this.state.noshow==-1&&appmark=='xjzb'?'display:none':''}>
          <View className='my-wdyue' onClick={this.opendetails.bind(this,'/pages/my/accountdetails',1)}>
            <Text className='my-jinezngcn my-wdmoneys'>{this.state.balance/100}</Text>
            <Text className='my-jinezngcn my-wdyejf'>余额</Text>
          </View>
          <View className='my-wdyue' onClick={this.opendetails.bind(this,'/pages/my/pointsdetails',2)} >
            <Text className='my-jinezngcn my-wdjifens'>{this.state.creditBalance/100}</Text>
            <Text className='my-jinezngcn my-wdyejf' style={appmark=='xjzb'?'':'display:none'}>WUC</Text>
            <Text className='my-jinezngcn my-wdyejf' style={appmark=='xjzb'?'display:none':''}>积分</Text>
          </View>
          <View className='my-wdyue' onClick={this.opendetails.bind(this,'/pages/my/dollardetails',3)} style={appmark=='xjzb'?'':'display:none'}>
            <Text className='my-jinezngcn my-wdzhubi'>{this.state.beanBalance/100}</Text>
            <Text className='my-jinezngcn my-wdyejf'>UC</Text>
          </View> 
          <View className='my-wdyue' onClick={this.open.bind(this,'/pages/my/xypage?id='+this.state.zjinfo.balanceCreditUc)} style={appmark=='xjzb'?'':'display:none'}>
            <Text className='my-jinezngcn my-wdzhubi'>{this.state.zjinfo.balanceCreditUc/100}</Text>
            <Text className='my-jinezngcn my-wdyejf'>授信额度</Text>
          </View> 
        </View> 
        <View className='my-money' style={this.state.noshow==-1?'display:none':''}>
        	<View className='my-wdyue' onClick={this.opendetails.bind(this,'/pages/my/ziqia',8)}>
	           <Text className='my-jinezngcn my-wdzhubi'>{this.state.indexK}</Text>
	           <Text className='my-jinezngcn my-wdyejf' style={appmark=='xjzb'?'':'display:none'}>自洽指数</Text>
	           <Text className='my-jinezngcn my-wdyejf' style={appmark=='xjzb'?'display:none':''}>贡献指数</Text>
	        </View> 
          <View className='my-wdyue' onClick={this.opendetails.bind(this,'/pages/my/jiazhi',10)}>
	           <Text className='my-jinezngcn my-wdzhubi'>{this.state.indexAssets/100}</Text>
	           <Text className='my-jinezngcn my-wdyejf' style={appmark=='xjzb'?'':'display:none'}>价值资产</Text>
	           <Text className='my-jinezngcn my-wdyejf' style={appmark=='xjzb'?'display:none':''}>消费贡献</Text>
	        </View> 
          <View className='my-wdyue' onClick={this.opendetails.bind(this,'/pages/my/zxzc',11)}>
	           <Text className='my-jinezngcn my-wdzhubi'>{this.state.balanceZxzc/100}</Text>
	           <Text className='my-jinezngcn my-wdyejf' style={appmark=='xjzb'?'':'display:none'}>专项资产</Text>
	           <Text className='my-jinezngcn my-wdyejf' style={appmark=='xjzb'?'display:none':''}>成长贡献</Text>
	        </View> 
	        <View className='my-wdyue' onClick={this.opendetails.bind(this,'/pages/my/xingyong',9)}>
	           <Text className='my-jinezngcn my-wdzhubi'>{this.state.indexCI/100}</Text>
	           <Text className='my-jinezngcn my-wdyejf' style={appmark=='xjzb'?'':'display:none'}>信用资产</Text>
	           <Text className='my-jinezngcn my-wdyejf' style={appmark=='xjzb'?'display:none':''}>任务贡献</Text>
	        </View> 
        </View>
		<View className='my-yhq my-order'>
			<View className="tit">
        		
        		<Text className="bt">我的{appmark=='xjzb'?'UC商城':'商城订单'}</Text>
        	</View>
			<View className='order-list'>
      <View className='order-lis'>
				<View className='order-li' onClick={this.goorder.bind(this,'/pages/my/unpaid','UNPAID')}>
					<Image mode='widthFix' className='ddimg' src={dd01}></Image>
					<Text className="ddtext">待付款</Text>
				</View>
         <View className="divright" style={this.state.order.unpaidNum>0?"":"display:none"}>{this.state.order.unpaidNum}</View>
      </View>
      <View className='order-lis'>
				<View className='order-li' onClick={this.goorder.bind(this,'/pages/my/unpaid','PAID')}>
					<Image mode='widthFix' className='ddimg' src={dd02}></Image>
					<Text className="ddtext">待出库</Text>
				</View>
        <View className="divright" style={this.state.order.deliveredNum>0?"":"display:none"}>{this.state.order.deliveredNum}</View>
        </View>

        <View className='order-lis'>
				<View className='order-li' onClick={this.goorder.bind(this,'/pages/my/unpaid','GOODS_RECEIVED')}>
					<Image mode='widthFix' className='ddimg' src={dd03}></Image>
					<Text className="ddtext">待确认</Text>
				</View>
        <View className="divright" style={this.state.order.goodsReceivedNum>0?"":"display:none"}>{this.state.order.goodsReceivedNum}</View>
        </View>

        <View className='order-lis'>
				<View className='order-li' onClick={this.goorder.bind(this,'/pages/my/unpaid','REFUND')}>
					<Image mode='widthFix' className='ddimg' src={dd04}></Image>
					<Text className="ddtext">退款订单</Text>
				</View>
        {/* <View className="divright" style={this.state.order.refundNum!=0?"":"display:none"}>{this.state.order.refundNum}</View> */}
        </View>

        <View className='order-lis'>
				<View className='order-li' onClick={this.goorder.bind(this,'/pages/my/unpaid','COMPLETED')}>
					<Image mode='widthFix' className='ddimg' src={dd05}></Image>
					<Text className="ddtext">已完成</Text>
				</View>
        {/* <View className="divright" style={this.state.order.completeNum!=0?"":"display:none"}>{this.state.order.completeNum}</View> */}
        </View>
			</View>
		</View>
        <View className='my-yhq'>
        	<View className="tit">
        		<Text className="qb" onClick={this.open.bind(this,'/pages/coupon/coupon')}>全部卡券</Text>
        		<Text className="bt">我的优惠券</Text>
        	</View>
        	<ScrollView className="my-yhqky" scrollX  style={result.length>0?'':'display:none;'}>
        		{result.map((item, index) => (   
        		<View className='yhq-dl'>
        				<View className="yhq-dt" onClick={this.openxq.bind(this,item.mallId,item.id)}>
        						<View style={item.publish.couponType.indexOf('DISCOUNT')>=0?'':'display:none'}>
        						<Text className="jg">{item.publish.ruleFavourData/10}</Text>
        						<Text className="tb"> 折</Text>
        						</View>
        						<View style={item.publish.couponType.indexOf('DISCOUNT')>=0?'display:none':''}>
        						<Text className="tb">¥</Text>
        						<Text className="jg">{item.publish.ruleFavourData/100}</Text>
        						</View>
        						<Text className="tj">{item.publish.summary}</Text>
        				</View>
        				<View className="yhq-dd">
        					<Text className="yhq-sy" onClick={this.openxq.bind(this,item.mallId,item.id)}>查看详情</Text>
        				</View>
        		</View>
        		))}
        	</ScrollView>
        </View>
        <View className='active-ol' style={appmark=='xjzb'?'':'display:none'}>
          <View className='active-order' onClick={this.gotowgm.bind(this,'/pages/my/unpaid','')}>
            <Image mode='scaleToFill' className='goods-photo' src='https://minichat.g2ma.com/kedouimg/myorder20.png'></Image>
            <Text className=''>WGM订单</Text>
          </View>
        <View className='active-ul'style={this.state.order.ucNum!=0?"":"display:none"}>{this.state.order.ucNum}</View>
        </View>

        <View className='active-ol'>
        <View className='receiving-address' onClick={this.opendetails.bind(this,'/pages/my/unpaid','WUC')}>
          <Image mode='scaleToFill' className='address-photo' src='https://minichat.g2ma.com/kedouimg/myorder.png'></Image>
          <Text className='' style={appmark=='xjzb'?'':'display:none'}>WUC订单</Text>
          <Text className='' style={appmark=='xjzb'?'display:none':''}>积分订单</Text>
        </View>
        <View className='active-ul'style={this.state.order.wucNum!=0?"":"display:none"}>{this.state.order.wucNum}</View>
        </View>

        <View className='active-order' onClick={this.opendetails.bind(this,'/pages/my/consumer','')}>
          <Image mode='scaleToFill' className='active-photo' src='https://minichat.g2ma.com/kedouimg/myorder3.png'></Image>
          <Text className=''>活动/消费订单</Text>
        </View>
        
        <View className='active-order' onClick={this.opendetails.bind(this,'/pages/card/cardlist')}>
          <Image mode='scaleToFill' className='active-photo' src={hyk}></Image>
          <Text className=''>我的会员卡</Text>
        </View>
        <View className='active-order' style="display:none" onClick={this.opendetails.bind(this,'/pages/pkgo/winningrecord')}>
          <Image mode='scaleToFill' className='active-photo' src='https://minichat.g2ma.com/kedouimg/myorder7.png'></Image>
          <Text className=''>中奖记录</Text>
        </View>
        <View className='receiving-address' onClick={this.opendetails.bind(this,'/pages/my/homeset')}>
          <Image mode='scaleToFill' className='address-photo' src='https://minichat.g2ma.com/kedouimg/myorder1.png'></Image>
          <Text className=''>设置</Text>
        </View>
        <View className='receiving-address' style="height:100rpx;"></View>
        <Footer porpNav="4"></Footer>
      </View>
    )
  }
}

 